// file: counter.js

/* 用于检测javascript版本 */
var _js_ver_str = "<script language=\"javascript\">var _js_version=\"1.0\";</script>";
_js_ver_str += "<script language=\"javascript1.1\">_js_version=\"1.1\";</script>";
_js_ver_str += "<script language=\"javascript1.2\">_js_version=\"1.2\";</script>";
_js_ver_str += "<script language=\"javascript1.3\">_js_version=\"1.3\";</script>";
_js_ver_str += "<script language=\"javascript1.4\">_js_version=\"1.4\";</script>";
_js_ver_str += "<script language=\"javascript1.5\">_js_version=\"1.5\";</script>";
_js_ver_str += "<script language=\"javascript1.6\">_js_version=\"1.6\";</script>";
_js_ver_str += "<script language=\"javascript1.7\">_js_version=\"1.7\";</script>";
_js_ver_str += "<script language=\"javascript1.8\">_js_version=\"1.8\";</script>";
_js_ver_str += "<script language=\"javascript1.9\">_js_version=\"1.9\";</script>";
document.write(_js_ver_str);
/**
 * 得到javascript版本
 */
function _GetJsVersion() {
	return _js_version;
}

/**
 * 是否启用了cookies
 */
function _IsCookieEnabled() {
	document.cookie = "counter_test_z=1; expires=Thu, 31-Dec-2037 23:55:55 GMT; path=/";
	if (document.cookie) {
		document.cookie = "counter_test_z=1; expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/";
		return "1";
	} else {
		return "0";
	}
}

/**
 * 得到网站访问计数值主方法
 */
function _GetCount(_width,_height) {
	//获得访问参数
	var _cookie_en = _IsCookieEnabled();
	var _js_version = _GetJsVersion();
	var _java_en = "0";
	var _screen_width = 0;
	var _screen_height = 0;
	var _screen_depth = 0;
	
	if(!_width || _width<1){ _width = 80; }
	if(!_height || _height<1){ _height = 20; }
	var _host = _counter_host;
	var _lb = _counter_lb;
	var _id = _counter_id;
	var _text = _counter_text;
	switch (_js_version) {
	  default:
	  case "1.2":
		_screen_width = screen.width;
		_screen_height = screen.height;
		_screen_depth = (navigator.appName.substring(0, 3) == "Mic") ? screen.colorDepth : screen.pixelDepth;
	  case "1.1":
		_java_en = navigator.javaEnabled() ? "1" : "0";
	  case "1.0":
	}
	//构建计数器对象src
	var _counter_src = "http://" + _host + "/bin/counter.do?lb=" + _lb + "&id=" + _id + 
			"&ck_en=" + _cookie_en + "&js_ver=" + _js_version + "&ja_en=" + _java_en + 
			"&sw=" + _screen_width + "&sh=" + _screen_height + "&sd=" + _screen_depth;
	if (_lb=="hide") {//什么也不显示
		var _img = new Image;
		_img.src = _counter_src;
		return;
	}
	//构建对象
	var _element_str = "";
	var _element_id = "_counter_" + _id + "_" + parseInt(Math.random()*100);
	if(_lb=="img"){
		//以图像方式显示
		_element_str += "<img id=\"" + _element_id + "\" alt=\"" + _text + "\" title=\"" + _text + "\" border=\"0\"";
		if (_width && _height) {
			_element_str += " style=\"width:" + _width + "px;height:" + _height + "px\"";
			_element_str += " width=\"" + _width + "\" height=\"" + _height;
		}
		_element_str += "\" />";
	}else if(_lb=="txt"){
		//以文本方式显示
		_element_str += "<iframe id=\"" + _element_id + "\" alt=\"" + _text + "\" title=\"" + _text + "\" frameborder=\"0\" marginwidth=\"5\" marginheight=\"0\" scrolling=\"no\"";
		if (_width && _height) {
			_element_str += " style=\"width:" + _width + "px;height:" + _height + "px\"";
			_element_str += " width=\"" + _width + "\" height=\"" + _height;
		}
		_element_str += "\"></iframe>";
	}
	//输出计数器对象
	document.write(_element_str);
	//赋值计数器src
	_img_element = document.getElementById(_element_id);
	if (_img_element) {
		_img_element.src = _counter_src;
	}
}

